package Tree;

import java.util.LinkedList;
import java.util.Queue;

public class _513_FindBottomLeftTreeValue {
    public int findBottomLeftValue(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        int res = root.val;
        queue.add(root);
        while (!queue.isEmpty()) {
            TreeNode temp = queue.peek();
            //note:as the question's ask,add from right to left,so
            //we can get the bottom's leftest node.
            if (temp.right != null) {
                queue.add(temp.right);
            }
            if (temp.left != null) {
                queue.add(temp.left);
            }
            res = queue.poll().val;
        }
        return res;
    }
}
